package com.lsh.payment.worker.task;

import com.alibaba.fastjson.JSON;
import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext;
import com.dangdang.ddframe.job.plugin.job.type.simple.AbstractSimpleElasticJob;
import com.lsh.base.trace.id.filter.TraceIdSetter;
import com.lsh.payment.core.model.notify.PayNotifyTask;
import com.lsh.payment.worker.service.PaymentNotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Project Name: lsh-payment
 *
 * @author peter
 * @date 16/11/9
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Component
public class PaymentNotifyJop extends AbstractSimpleElasticJob {

    private static Logger logger = LoggerFactory.getLogger(PaymentNotifyJop.class);

    @Autowired
    private PaymentNotifyService paymentNotifyService;

    @Override
    public void process(JobExecutionMultipleShardingContext jobContext) {
        TraceIdSetter.set();
        List<PayNotifyTask> payNotifyTaskList = paymentNotifyService.selectTasks();

        if(CollectionUtils.isEmpty(payNotifyTaskList)){
            logger.info("Jop payNotifyTmsTaskList is empty");
            return ;
        }

        for (PayNotifyTask payNotifyTask : payNotifyTaskList) {
            logger.info("Jop 处理回调信息 : " + JSON.toJSONString(payNotifyTask));
            paymentNotifyService.dealNotify(payNotifyTask);
        }
    }

}
